import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem('token'),
    userInfo: JSON.parse(sessionStorage.getItem('userInfo'))
  },
  //这个就相当于java的set方法
  mutations: {
    SET_TOKEN:(state, token)=>{
      state.token = token
      localStorage.setItem('token',token)
    },
    SET_USERINFO:(state, userinfo)=>{
      state.userInfo = userinfo
      sessionStorage.setItem('userInfo',JSON.stringify(userinfo))
    },
    //这里还要搞一个移除的方法
    REMOVE_INFO:(state)=>{
      state.token = ''
      state.userInfo = {}
      localStorage.setItem('token','')
      sessionStorage.setItem('userInfo',JSON.stringify(''))
    }
  },
  getters:{
    getUserInfo:state=>{
      return state.userInfo
    }
  },
  actions: {
  },
  modules: {
  }
})
